package com.zhika.zishi.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.zhika.zishi.R;
import com.zhika.zishi.adapter.StrategyFragmentAdapter;
import com.zhika.zishi.customview.Bottom2View;
import com.zhika.zishi.customview.TitleView;
import com.zhika.zishi.fragments.StrategyFragment;
import com.zhika.zishi.interfaces.Bottom2Interface;
import com.zhika.zishi.interfaces.TitleInterface;
import com.zhika.zishi.util.ActivityCollector;

import java.util.ArrayList;

/**
 * Created by shi-02 on 2015/4/9.
 */
public class StrategyDetailsActivity extends FragmentActivity implements View.OnClickListener,TitleInterface,Bottom2Interface {

    private ViewPager viewPager;

    private ImageView triangleImageView;

    private TextView strategyInfoText;

    private TitleView titleView;

    private Bottom2View bottomView;


    private ArrayList<StrategyFragment> strategyFragmentList = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        ActivityCollector.addActivity(this);
        setContentView(R.layout.strategy_details_layout);

        addFragments();

        initView();
    }

    private void initView(){
        viewPager = (ViewPager) findViewById(R.id.strategy_details_view_pager);
        StrategyFragmentAdapter adapter = new StrategyFragmentAdapter(getSupportFragmentManager(),strategyFragmentList);
        viewPager.setAdapter(adapter);

        triangleImageView = (ImageView) findViewById(R.id.strategy_details_triangle_image_view);

        strategyInfoText = (TextView) findViewById(R.id.strategy_details_strategy_info_text);
        strategyInfoText.setOnClickListener(this);

        titleView = (TitleView) findViewById(R.id.strategy_details_title_view);
        titleView.setTitleViewInterface(this);
        titleView.setLeftButtonText("返回");
        titleView.setMiddleRowText("攻略标题");
        titleView.setRightButtonText("更多");

        bottomView = (Bottom2View) findViewById(R.id.strategy_details_bottom_view);
        bottomView.setBottom2Interface(this);

    }

    private void addFragments(){
        for (int i=0;i<3;i++){
            strategyFragmentList.add(new StrategyFragment());
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityCollector.remoteActivity(this);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.strategy_details_strategy_info_text:
                strategyInfoTextListener();
                break;
            default:
                break;
        }
    }

    @Override
    public void leftBottom2Listener() {
        Toast.makeText(StrategyDetailsActivity.this,"评论",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void middleLeftBottom2Listener() {
        Toast.makeText(StrategyDetailsActivity.this,"收藏",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void middleRightBottom2Listener() {
        Toast.makeText(StrategyDetailsActivity.this,"点赞",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void rightBottom2Listener() {

        //对比秀的点击事件
        Intent intent = new Intent(StrategyDetailsActivity.this,CompareShowActivity.class);
        startActivity(intent);
    }

    /**
     * 攻略标题详情的点击事件
     */
    private void strategyInfoTextListener(){
        strategyInfoText.setVisibility(View.GONE);
    }

    @Override
    public void leftTitleListener() {
          finish();
    }

    @Override
    public void middleTitleListener() {
        strategyInfoText.setVisibility(View.VISIBLE);
    }

    @Override
    public void rightTitleListener() {

    }
}
